# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2022年01月13日
"""
import requests
from lxml import etree
import os
import time

if not os.path.exists('./财务资料'):
	os.mkdir('./财务资料')

url = "https://www.jkl.com.cn/newsList.aspx"
headers = {
	"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}
for i in range(1,3):
	params = {
		"current": i,
		"TypeId": "10009"
	}
	resp=requests.get(url=url, headers=headers, params=params).text
	data = etree.HTML(resp)
	links = data.xpath('//div[@class="newsLis"]//ul//@href')
	file_name = data.xpath('//div[@class="newsLis"]//li/a/text()')
	keys = []
	values = []

	for name in file_name:
		name = name.strip()
		keys.append(name)
	for link in links:
		link = 'http://www.jkl.com.cn'+link
		values.append(link)
	print(keys)
	print(values)
	字典 = dict(zip(keys, values))
	for key,value in 字典.items():
		后缀=value.split('.')[-1]
		file_data = requests.get(url=value,headers=headers).content
		path = './财务资料/'+key+'.'+后缀
		with open(path,'wb') as f :
			f.write(file_data)
			time.sleep(1)

